package com.hqd.ch03.v51.boot.context;

import com.hqd.ch03.v51.beans.factory.NoSuchBeanDefinitionException;
import com.hqd.ch03.v51.boot.WebApplicationType;
import com.hqd.ch03.v51.boot.web.context.WebServerApplicationContext;
import com.hqd.ch03.v51.boot.web.server.WebServerFactory;

public class MissingWebServerFactoryBeanException extends NoSuchBeanDefinitionException {

    private final WebApplicationType webApplicationType;

    /**
     * Create a new {@code MissingWebServerFactoryBeanException}.
     *
     * @param webServerApplicationContextClass the class of the
     *                                         WebServerApplicationContext that required the WebServerFactory
     * @param webServerFactoryClass            the class of the WebServerFactory that was missing
     * @param webApplicationType               the type of the web application
     */
    public MissingWebServerFactoryBeanException(
            Class<? extends WebServerApplicationContext> webServerApplicationContextClass,
            Class<? extends WebServerFactory> webServerFactoryClass, WebApplicationType webApplicationType) {
        super(webServerFactoryClass, String.format("Unable to start %s due to missing %s bean",
                webServerApplicationContextClass.getSimpleName(), webServerFactoryClass.getSimpleName()));
        this.webApplicationType = webApplicationType;
    }

    /**
     * Returns the type of web application for which a {@link WebServerFactory} bean was
     * missing.
     *
     * @return the type of web application
     */
    public WebApplicationType getWebApplicationType() {
        return this.webApplicationType;
    }

}
